<?php

namespace api\libs\notifications\models;

use api\libs\notifications\NotificationsModule;
use Yii;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "notification".
 *
 * @property integer $id
 * @property string $key_id
 * @property string $key
 * @property integer $type
 * @property integer $business_type
 * @property boolean $seen
 * @property boolean $flashed
 * @property string $created_at
 * @property integer $user_id
 * @property string $params
 */
abstract class Notification extends ActiveRecord
{

    /**
     * Default notification
     */
    const TYPE_DEFAULT = 1;
    /**
     * template notification
     */
    const TYPE_TEMPLATE   = 2;

    

    /**
     * @var array List of all enabled notification types
     */
    public static $types = [
        self::TYPE_DEFAULT,
        self::TYPE_TEMPLATE,
    ];

    
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%notification_record}}';
    }


    /**
     * Creates a notification
     *
     * @param string $key
     * @param integer $user_id The user id that will get the notification
     * @param string $key_id The foreign instance id
     * @param string $type
     * @return bool Returns TRUE on success, FALSE on failure
     * @throws \Exception
     */
    public static function notify($type = self::TYPE_DEFAULT, $user_id, $template_id = null, $params = [], $campaign_id = 0)
    {
        $class = self::className();
        return NotificationsModule::notify(new $class(), $type, $user_id, $template_id, $params, $campaign_id);
    }
    

}
